package com.gaeainfo.modules.alarm.feedback.dao;

import com.gaeainfo.modules.alarm.feedback.entity.FeedbackAttEntity;
import com.gaeainfo.modules.alarm.feedback.entity.FeedbackEntity;
import com.gaeainfo.modules.base.dao.BaseHibernateDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by Caven on 2018/7/13.
 */

@Repository("alarmFeedbackDao")
public class AlarmFeedbackDaoImpl extends BaseHibernateDao implements AlarmFeedbackDao {


    @Override
    public void createFeedback(FeedbackEntity feedbackEntity) {
        this.save(feedbackEntity);
    }

    @Override
    public FeedbackEntity findFeedbackById(String feedbackId) {
        return this.get(FeedbackEntity.class, feedbackId);
    }

    @Override
    public FeedbackEntity findFeedbackByProcessId(String processId) throws Exception {
        return null;
    }

    @Override
    public void updateFeedback(FeedbackEntity feedbackEntity) {
        this.update(feedbackEntity);
    }

    @Override
    public void createFeedbackAtt(FeedbackAttEntity feedbackAttEntity) {
        this.save(feedbackAttEntity);
    }

    @Override
    public FeedbackAttEntity findFeedBackAttById(String feedbackId, String fileId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(FeedbackAttEntity.class);
        criteria.add(Restrictions.eq("feedbackId", feedbackId))
                .add(Restrictions.eq("attId", fileId));
        List<FeedbackAttEntity> list = this.findByCriteria(criteria);
        if (list != null && !list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<FeedbackAttEntity> findFeedbackAttByFeedbackId(String feedbackId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(FeedbackAttEntity.class);
        criteria.add(Restrictions.eq("feedbackId", feedbackId));
        return this.findByCriteria(criteria);
    }

    @Override
    public void deleteFeedbackAtt(FeedbackAttEntity feedbackAttEntity) {
        this.delete(feedbackAttEntity);
    }
}
